<?php

//require 'class/feld.class.php';

class Twitterstream extends Feld {
	
	public $id;
	public $value;
	public $typ;
	public $label;
	
	public function Twitterstream($id,$value,$typ,$label){
		$this->id = $id;
		$this->value = $value;
		$this->typ = $typ;
		$this->label = $label;
	}
	
	public function getCode($wert=null,$label=null,$fehler=null){
		echo("<tr><td>".$this->typ."</td><td><input type='text' name='".$this->id."label' value='".$this->label."' /></td><td><input type='text' name='".$this->id."' value='".$this->value."' /></td></tr>");
		
		//print_r($_SESSION);
		try {
		
		$rssPfad = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=".$this->value."&count=5";
		$xml = new DOMDocument('1.0', 'UTF-8');
		$xml->preserveWhiteSpace = FALSE;
		@$xml->load($rssPfad);
		echo "<tr><td></td><td></td><td><table>";
		
		$count = 0;
		
		while($dateNode = $xml->getElementsByTagName('pubDate')->item($count)){
			$date=$dateNode->nodeValue;
			$tweet = utf8_decode($xml->getElementsByTagName('title')->item($count+1)->nodeValue);
			echo "<tr><td>$date</td><td>$tweet</td></tr>";
			$count++;
		}
		echo "</table></td></tr>";
		
		} catch (Exception $e) {
			echo "Leider gab es ein Problem beim Abrufen der Tweets.";
		}

	}
	
	public function getVCard($nummer){
		return "";
	}
	
	public static function validate($typ, $wert){
		
		//TODO @Lukas (Twitter-Validierung) muss noch erstellt werden	

		//preg_match("/[\w_]*/", $wert);
		return null;
	}
	
}

?>